package com.jams.goodox.activity.home;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.entity.GoodBuyBean;
import com.jams.goodox.utils.StyleUtil;
import com.jams.goodox.widget.NoScrollGridView;
import com.jams.goodox.widget.NoScrollListView;
import com.jams.library.commonAdapter.ListCommonAdapter;
import com.jams.library.commonAdapter.ListCommonViewHolder;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/10/8.
 */

public class OrderDetailActivity extends BaseActivity {

    @Bind(R.id.tx_order_status)
    TextView txOrderStatus;
    @Bind(R.id.tx_order_number)
    TextView txOrderNumber;
    @Bind(R.id.linear_order_do)
    LinearLayout linearOrderDo;
    @Bind(R.id.tx_jf)
    TextView txJf;
    @Bind(R.id.list_no_scroll)
    NoScrollListView listNoScroll;
    @Bind(R.id.tx_remark)
    TextView txRemark;
    @Bind(R.id.tx_money_type)
    TextView txMoneyType;
    @Bind(R.id.tx_pay_type)
    TextView txPayType;
    @Bind(R.id.tx_yunshu)
    TextView txYunshu;
    @Bind(R.id.tx_address)
    TextView txAddress;
    @Bind(R.id.textView4)
    TextView textView4;
    @Bind(R.id.tx_link)
    TextView txLink;
    @Bind(R.id.tx_remark_detail)
    TextView txRemarkDetail;
    @Bind(R.id.tx_real_money)
    TextView txRealMoney;

    private OrderResp.DataBean orderBean;

    @Override
    protected int getLayoutId() {
        return R.layout.order_detail_activity;
    }

    @Override
    protected void init() {
        StyleUtil.titleBackKeyWithRightIconListener(this, "订单详情", R.mipmap.icon_phone, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        orderBean = (OrderResp.DataBean) getIntent().getSerializableExtra("orderBean");
        setListViewAdapter();
        txOrderStatus.setText(orderBean.getProcess().get(0).getTitle());
        txOrderNumber.setText(String.format("订单号：%s", orderBean.getOrdersn()));
        txMoneyType.setText(String.format("%s件  ¥%s",orderBean.getNum(),orderBean.getPayable()));
        txPayType.setText(orderBean.getPayType());
        txYunshu.setText(orderBean.getTransit());
        OrderResp.DataBean.InfoBean infoBean=orderBean.getInfo();
        txAddress.setText(String.format("%s\n%s",infoBean.getCity(),infoBean.getAddress()));
        txLink.setText(infoBean.getUserName()+" "+infoBean.getMobile());
        txRealMoney.setText("¥"+orderBean.getPayable());
    }

    private void setListViewAdapter() {
        if (orderBean.getProduct() == null) return;
        listNoScroll.setAdapter(new ListCommonAdapter<OrderResp.DataBean.ProductBean>(this, orderBean.getProduct(), R.layout.order_fragment_list_item) {
            @Override
            public void convert(ListCommonViewHolder helper, OrderResp.DataBean.ProductBean item, int position) {
                helper.setText(R.id.tx_order_code, item.getTitle());
                helper.setViewVisible(R.id.tx_time, false);
                helper.setText(R.id.tx_price_number, String.format("¥%s   *%s", item.getPrice(), item.getNum()));
                NoScrollGridView grid_good_ms = helper.getView(R.id.grid_good_ms);
                grid_good_ms.setFocusable(false);
                grid_good_ms.setAdapter(new ListCommonAdapter<GoodBuyBean.Data.OptionBean>(OrderDetailActivity.this, item.getOption(), R.layout.shop_type_item) {
                    @Override
                    public void convert(ListCommonViewHolder helper, GoodBuyBean.Data.OptionBean item, int position) {
                        helper.setText(R.id.tx_type, String.format("%s/%s", item.getOptionKey(), item.getName()));
                    }
                });
            }
        });
    }

    @OnClick(R.id.tx_order_status)
    public void onClick() {
        Intent in = new Intent(this, OrderFlowActivity.class);
        in.putExtra("orderBean", orderBean);
        startActivity(in);
    }

}
